<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="停车场" prop="roleName">
        <el-select v-model="queryParams.plCode" size="small" filterable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.plCode"
            :label="item.plName"
            :value="item.plCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="车位号" prop="spaceCode">
        <el-input
          v-model="queryParams.spaceCode"
          placeholder="请输入车位号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:role:remove']"
        >删除无法上传指引图问题</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeletes"
          v-hasPermi="['system:role:remove']"
        >删除显示两条一样的车位</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="归属停车场" prop="plName" width="120" />
      <el-table-column label="车位号" prop="spaceCode"   width="100" />
      <el-table-column label="物权人" prop="propertyPerson" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="使用人" prop="userPerson" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="使用电话" prop="userPhone" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="使用性质" prop="nature" :formatter="usenature"  width="150" />
      <el-table-column label="使用人是否有分享权" align="center" width="150">
        <template  slot-scope="scope">
          <span>{{scope.row.isShare |getYn}}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否允许物业分享车位" align="center" width="150">
        <template  slot-scope="scope">
          <span>{{scope.row.platformIsShare | getYn}}</span>
        </template>
      </el-table-column>
      <el-table-column label="车位类型" align="center" width="100">
        <template  slot-scope="scope">
          <span>{{scope.row.spaceType |getStall}}</span>
        </template>
      </el-table-column>
      <el-table-column label="车位功能状态" align="center" width="100">
        <template  slot-scope="scope">
          <span>{{scope.row.spaceState |getSelfIsShare}}</span>
        </template>
      </el-table-column>
      <el-table-column label="车位分享" align="center" width="100">
        <template  slot-scope="scope">
          <span>{{scope.row.selfIsShare |getShare}}</span>
        </template>
      </el-table-column>
      <el-table-column label="车位当前状态" align="center" width="100">
        <template  slot-scope="scope">
          <span>{{scope.row.isOccupy |getOccupy}}</span>
        </template>
      </el-table-column>
      <el-table-column label="车位描述" prop="remark" :show-overflow-tooltip="true" width="150" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listPark, getparkSpace, getparkingSpace,delParkingSpace ,delParkingSpaces, delSysPark,  changeRoleStatus } from "@/api/park/park";

export default {
  name: "Park",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      options: [],
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限"
        },
        {
          value: "2",
          label: "自定数据权限"
        },
        {
          value: "3",
          label: "本部门数据权限"
        },
        {
          value: "4",
          label: "本部门及以下数据权限"
        },
        {
          value: "5",
          label: "仅本人数据权限"
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        page: 1,
        size: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" }
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_park_operStatus").then(response => {
      this.statusOptions = response.data;
    });
    this.getParkLot();
  },
  methods: {
    /** 查询同步列表 */
    getList() {
      this.loading = true;
      getparkingSpace(this.addDatePark(this.queryParams, this.dateRange)).then(
        response => {
          this.roleList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 办理状态
    statusFormat(row, column) {
      return this.getPark(row.operStatus);
    },
    // 保存类型
    statusOperation(row, column) {
      return this.getParkOperation(row.operType);
    },

    //使用性质
    usenature(row,column){
      return this.getuseNature(row.nature);
    },

    //是否
    Yn(row,column){
      return this.getYn(row.isShare);
    },

    //停车场
    getParkLot(){
      getparkSpace().then(
        response =>{
          this.options = response.data;
        }
      )
    },


    /** 查询菜单树结构 */
    getMenuTreeselect() {
      menuTreeselect().then(response => {
        this.menuOptions = response.data;
      });
    },
    /** 查询部门树结构 */
    getDeptTreeselect() {
      deptTreeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 所有菜单节点数据
    getMenuAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    // 所有部门节点数据
    getDeptAllCheckedKeys() {
      // 目前被选中的部门节点
      let checkedKeys = this.$refs.dept.getCheckedKeys();
      // 半选中的部门节点
      let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    /** 根据角色ID查询菜单树结构 */
    getRoleMenuTreeselect(roleId) {
      return roleMenuTreeselect(roleId).then(response => {
        this.menuOptions = response.menus;
        return response;
      });
    },
    /** 根据角色ID查询部门树结构 */
    getRoleDeptTreeselect(roleId) {
      return roleDeptTreeselect(roleId).then(response => {
        this.deptOptions = response.depts;
        return response;
      });
    },
    // 角色状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$confirm('确认要"' + text + '""' + row.roleName + '"角色吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return changeRoleStatus(row.roleId, row.status);
        }).then(() => {
          this.msgSuccess(text + "成功");
        }).catch(function() {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      this.menuExpand = false,
      this.menuNodeAll = false,
      this.deptExpand = true,
      this.deptNodeAll = false,
      this.form = {
        roleId: undefined,
        roleName: undefined,
        roleKey: undefined,
        roleSort: 0,
        status: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.plCode = null
      this.queryParams.operStatus = null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.id || this.ids;
      if(roleIds.length>1){
        this.$message.error('只能选择一条')
        return
      }
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delParkingSpace(roleIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },

  }
};
</script>
